﻿Namespace My

	' The following events are available for MyApplication:
	' 
	' Startup: Raised when the application starts, before the startup form is created.
	' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
	' UnhandledException: Raised if the application encounters an unhandled exception.
	' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
	' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
	Partial Friend Class MyApplication
		Private man As clsNotificationsManager

		Public ReadOnly Property Manager() As clsNotificationsManager
			Get
				Return man
			End Get
		End Property

		Protected Overrides Function OnStartup(ByVal eventArgs As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) As Boolean
			Dim result As Boolean = MyBase.OnStartup(eventArgs)
			man = New clsNotificationsManager()
			Try
				modCommon.RegisterFirstRun(True)
			Catch ex As Exception
				MessageBox.Show(ex.Message.Trim(), "Error(s) while application startup", _
					   MessageBoxButtons.OK, MessageBoxIcon.Error)
				modCommon.RegisterException(ex)
			End Try
			Return result
		End Function

		Protected Overrides Sub OnShutdown()
			If man IsNot Nothing Then
				man.Dispose()
				man = Nothing
			End If
			If clsNotificationImage.SystemImages IsNot Nothing Then
				clsNotificationImage.SystemImages.Clear()
			End If
			MyBase.OnShutdown()
		End Sub

		Protected Overrides Function OnUnhandledException(ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) As Boolean
			If e Is Nothing Then Return False
			modCommon.RegisterException(e.Exception)
			e.ExitApplication = False
			Return MyBase.OnUnhandledException(e)
		End Function
	End Class

End Namespace

